package com.fullhome8.cn.wanghongweb.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;

import java.util.Optional;

/**
 * kafka监听器
 */
public class KafkaListeners {

    @KafkaListener(topics = {"kjTest","replicated-kafkatopic"})
    public void testListener(ConsumerRecord<?, ?> record) {
        System.out.printf("======" + record);
        if ("kjTest".equals(record.topic())) {
            System.out.printf("==topic:" + "这是区分我的微信标识哈哈");
        }
        Optional<?> messages = Optional.ofNullable(record.value());
        if (messages.isPresent()) {
            Object msg = messages.get();
            System.out.println("get message from kafka: " + msg);
        }
    }
}
